package com.steven.web.controller;


import com.steven.web.po.JsonAnnotationPo;
import com.steven.web.po.TUser;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Author:      Steven<br>
 * Date:        2021/1/16<br>
 * Version:     V1.0.0<br>
 * Update:     <br>
 */
@Controller
public class UserController {

    @GetMapping("/user")
    public ModelAndView getUser() {
        List<TUser> users = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            TUser user = new TUser();
            user.settUId(123L + i);
            user.settUName("jack" + i);
            user.setBirthday(new Date());
            users.add(user);
        }
        ModelAndView mv = new ModelAndView();
        mv.setViewName("users");
        mv.addObject("users", users);
        return mv;
    }
    @GetMapping("getJsonData")
    @ResponseBody
    public JsonAnnotationPo jsonTest(){
        JsonAnnotationPo jd=new JsonAnnotationPo();
        jd.setJName("name_v");
        jd.setJAddress("add_v");
        jd.setAge(12);
        jd.setJIgnore1("ig1");
        jd.setJIgnore2("ig2");
        jd.setJBirthday(new Date());
        return jd;
    }

    @GetMapping("CORSTest")
    public ModelAndView corsTest(){
        ModelAndView mv=new ModelAndView();
        mv.setViewName("CORSTest");
        return mv;
    }

}
